package kr.co.bettersoftportal.site.management.dao;

import kr.co.bettersoftportal.site.domain.NoticeBoard;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import java.util.List;


public class NoticeBoardDaoImpl extends SqlMapClientDaoSupport implements NoticeBoardDao {

    // SLF4J Logging
    private Logger logger = LoggerFactory.getLogger(NoticeBoardDaoImpl.class);

    public List getBoardListBySearchword(NoticeBoard board) {


        /**
         * Null 에러 방지용 공백 전환
         */
        if(board.getTitle() == null){
            board.setTitle("");
        }

        if(board.getWriter_id() == null){
            board.setWriter_id("");
        }

        if(board.getWriter_nick_name() == null){
            board.setWriter_nick_name("");
        }

        if(board.getContent() == null){
            board.setContent("");
        }

        return getSqlMapClientTemplate().queryForList("NBOARD.getBoardListBySearchword", board, board.getCurrentPage() * board.getPageSize(), board.getPageSize());
    }

    public List getBoardListByNo(NoticeBoard board){
        return getSqlMapClientTemplate().queryForList("NBOARD.getBoardListByNo", board, board.getCurrentPage() * board.getPageSize(), board.getPageSize());
    }

    public String getTotalCountBySearchword(NoticeBoard board) {
        return (String)getSqlMapClientTemplate().queryForObject("NBOARD.getTotalCountBySearchword", board);
    }

    public String getTotalCountByNo(NoticeBoard board) {
        return (String)getSqlMapClientTemplate().queryForObject("NBOARD.getTotalCountByNo", board);
    }

    public String writeBoard(NoticeBoard board){
        return Integer.toString(getSqlMapClientTemplate().update("NBOARD.writeBoard", board));
    }

    public String updateBoard(NoticeBoard board){
        return Integer.toString(getSqlMapClientTemplate().update("NBOARD.updateBoard", board));
    }

    public String deleteBoard(NoticeBoard board){
        return Integer.toString(getSqlMapClientTemplate().update("NBOARD.deleteBoard", board));
    }

    public NoticeBoard getBoardByNo(String notice_board_no){
        return (NoticeBoard)getSqlMapClientTemplate().queryForObject("NBOARD.getBoardByNo", notice_board_no);
    }

    public String updateReplyCount(NoticeBoard board){
        return Integer.toString(getSqlMapClientTemplate().update("NBOARD.updateReplyCount", board));
    }

    public String updateHitCount(NoticeBoard board){
        return Integer.toString(getSqlMapClientTemplate().update("NBOARD.updateHitCount", board));
    }

    public String updateVoteCount(NoticeBoard board){
        return Integer.toString(getSqlMapClientTemplate().update("NBOARD.updateVoteCount", board));
    }

    public String updateNegativeCount(NoticeBoard board){
        return Integer.toString(getSqlMapClientTemplate().update("NBOARD.updateNegativeCount", board));
    }

    public String updateReportCount(NoticeBoard board){
        return Integer.toString(getSqlMapClientTemplate().update("NBOARD.updateReportCount", board));
    }

    public String updateBoardNotImage(NoticeBoard board) {
        return Integer.toString(getSqlMapClientTemplate().update("NBOARD.updateBoardNotImage", board));
    }
}
